package member.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import library.domain.Member;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class MemberDAO {
	
	private SqlMapClientTemplate sqlMap;
	public MemberDAO(SqlMapClientTemplate sqlmap) {
		this.sqlMap = sqlmap;
	}
	
	public void insertMember(Member member) throws SQLException{
		sqlMap.insert("insertMember", member);
	}
	public int updateMember(Member member) throws SQLException{
		return sqlMap.update("updateMember", member);
	}
	public int updateMemberByRegisterNo(Member member) throws SQLException{
		return sqlMap.update("updateMemberByRegisterNo", member);
	}
	public int deleteMemberById(String member_id) throws SQLException{
		return sqlMap.delete("deleteMemberById", member_id);
	}
	public Member selectMemberById(String member_id) throws SQLException{
		return (Member)sqlMap.queryForObject("selectMemberById", member_id);
	}
	public Member selectMemberByRegisterNo(String register_no1, String register_no2) throws SQLException{
		HashMap map = new HashMap();
		map.put("registerNo1", register_no1);
		map.put("registerNo2", register_no2);
		return (Member)sqlMap.queryForObject("selectMemberByRegisterNo", map);
	}
	public ArrayList<Member> selectMemberByName(String member_name) throws SQLException{
		return (ArrayList<Member>)sqlMap.queryForList("selectMemberByName", member_name);
	}
	public ArrayList<Member> selectAllMember() throws SQLException{
		return (ArrayList<Member>)sqlMap.queryForList("selectAllMember");
	}
	public Member selectMemberByIdJoinBook(String member_id) throws SQLException{
		return (Member)sqlMap.queryForObject("selectMemberByIdJoinBook", member_id);
	}
	public ArrayList<Member> selectAllMemberRentingBooks() throws SQLException{
		return (ArrayList<Member>)sqlMap.queryForList("selectAllMemberJoinBook");
	}
}
